#ifndef __PROG_GROUP_H
#define __PROG_GROUP_H

#include "stdint.h"

#ifdef __cplusplus
extern "C"
{
#endif

#define PG_ERR_NONE 0
#define PG_ERR_TAB_FULL -1
#define PG_ERR_PHY_REUSE -2
#define PG_ERR_SEG_REUSE -3
#define PG_ERR_PHY_NOUSE -4
#define PG_ERR_SEG_NOUSE -5
#define PG_ERR_GROUP_NOUSE -6
#define PG_ERR_SUB_FULL -7

	typedef unsigned char pg_gp_site_t;
	typedef unsigned char pg_sub_site_t;
	typedef unsigned char pg_phy_site_t;

	struct pg_element_str
	{
		pg_gp_site_t group; 
		pg_sub_site_t sub;	
		pg_phy_site_t phy;	
	};

	struct pg_man_str
	{
		struct pg_element_str *tab; 
		pg_phy_site_t tab_size;		
		pg_gp_site_t group_max;		
		pg_sub_site_t sub_max;		
									
		char head_fix;				
		char cycle;					
		
		pg_phy_site_t act_num; 
		int8_t err;			   
		
		pg_phy_site_t site; 
		pg_gp_site_t group; 
		pg_sub_site_t sub;	
		pg_phy_site_t phy;	
	};

	int8_t pg_init(struct pg_man_str *, struct pg_element_str *tab, pg_phy_site_t tab_size);
	int8_t pg_mode(struct pg_man_str *, char head_fix, char cycle);
	int8_t pg_size(struct pg_man_str *, pg_gp_site_t group_max, pg_sub_site_t sub_max);

	int8_t pg_add(struct pg_man_str *, pg_gp_site_t group, pg_sub_site_t sub, pg_phy_site_t phy);
	int8_t pg_del_phy(struct pg_man_str *, pg_phy_site_t phy);
	int8_t pg_del_seg(struct pg_man_str *, pg_gp_site_t group, pg_sub_site_t sub);

	int8_t pg_phy_site(struct pg_man_str *, pg_phy_site_t phy);
	int8_t pg_seg_site(struct pg_man_str *, pg_gp_site_t group, pg_sub_site_t sub);
	int8_t pg_next_phy(struct pg_man_str *, pg_phy_site_t phy);
	int8_t pg_next_seg(struct pg_man_str *, pg_gp_site_t group, pg_sub_site_t sub);
	int8_t pg_fore_phy(struct pg_man_str *, pg_phy_site_t phy);
	int8_t pg_fore_seg(struct pg_man_str *, pg_gp_site_t group, pg_sub_site_t sub);

	int8_t pg_group_site(struct pg_man_str *, pg_gp_site_t group);

	int8_t pg_gp_sapce_sub_get(struct pg_man_str *, pg_gp_site_t group);

	pg_phy_site_t pg_seg_amount(struct pg_man_str *);
	pg_phy_site_t pg_gp_seg_amount(struct pg_man_str *pg, pg_gp_site_t group);

#ifdef __cplusplus
}
#endif

#endif 
